//
//  SocketIOClient.h
//  Socket.IO-Client
//
//  Created by alanwang.dev on 16/8/8.
//  Copyright © 2016年 com.alanwang.dev. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SocketEngineSpec.h"
#import "SocketEngine.h"
#import "SocketIOClientOption.h"
#import "SocketParsable.h"
#import "SocketEngineClient.h"
#import "SocketAnyEvent.h"

typedef enum : NSUInteger {
    NotConnected,
    Disconnected,
    Connecting,
    Connected,
    Reconnecting
} SocketIOClientStatus;

typedef void(^CompleteHandler)();

@class SocketEngine;

@interface SocketIOClient : SocketParsable <SocketEngineClient, SocketParsableProtocol>
@property (nonatomic, strong) NSURL *socketURL;

@property (nonatomic, readonly) SocketEngineSpec* engine;
@property (nonatomic, readonly) SocketIOClientStatus status;

@property (nonatomic, assign) BOOL forceNew;
@property (nonatomic, copy) NSString *nsp;
@property (nonatomic) NSMutableDictionary *options;
@property (nonatomic, assign) BOOL reconnects;
@property (nonatomic, assign) NSInteger reconnectWait;
@property (nonatomic, copy) NSString *sid;

- (instancetype)initWithSocketURL:(NSURL *)socketURL options:(NSDictionary *)options;
- (void)connect;
- (void)connect:(NSInteger)timeoutAfter complete:(CompleteHandler)handler;
- (void)didConnect;
- (void)didDisconnect:(NSString *)reason;
- (void)disconnect;
/// send a message to the server
- (void)emit:(NSString *)event withItems:(NSArray *)items;
- (OnAckCallBack)emitWithAck:(NSString *)event items:(NSArray *)items;
- (void)_emit:(NSArray *)data ack:(NSInteger)ack;
- (void)emitAck:(NSInteger)ack items:(NSArray *)items;
- (void)engineDidClose:(NSString *)reason;
- (void)engineDidError:(NSString *)reason;
- (void)engineDidOpen:(NSString *)reason;
- (void)handleAck:(NSInteger)ack data:(NSArray *)data;
- (void)handleEvent:(NSString *)event data:(NSArray *)data isInternalMessage:(BOOL)isIntelMsg ack:(NSInteger)ack;
- (void)leaveNamespace;
- (void)joinNamespace:(NSString *)Namespace;
- (void)offWithEvent:(NSString *)event;
- (void)offWithId:(NSUUID *)id;
- (NSUUID *)on:(NSString *)event callback:(NormalCallback)callback;
- (NSUUID *)once:(NSString *)event callback:(NormalCallback)callback;
- (void)onAny:(void(^)(SocketAnyEvent *))handler;
- (void)parseEngineMessage:(NSString *)msg;
- (void)parseEngineBinaryData:(NSData *)data;
- (void)reconnect;
- (void)removeAllHandlers;
- (void)close;

@end
